<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>07_防抖-基本使用2</title>
        <style>
            div {
                width: 300px;
                height: 300px;
                border: 1px solid black;
            }
        </style>
    </head>
    <body>
        <div>1</div>

        <script>
            var div = document.querySelector('div');


            function move(){
                div.innerHTML++;
            }

            var timer = null;
            function debounce(func){
                return function(){
                    clearTimeout(timer);
                    timer = setTimeout(function(){
                        func();
                    },2000);
                }

            }


            div.addEventListener('mousemove',debounce(move));
        </script>
    </body>
</html>